package com.naiterui.ehp.bs.cms.modules.agent.util;

import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.zip.ZipFile;

/**
 * @author yiren
 * @since 2022/3/3
 */
public class ZipFIleUtil {
    private static final String[] charsets = new String[]{"GBK", "UTF-8"};
    public static Charset getCharset(String zipPath) {
        for (String item : charsets) {
            Charset charset = Charset.forName(item);
            try (ZipFile zipFile = new ZipFile(zipPath, charset)) {
                for (Enumeration entries = zipFile.entries(); entries.hasMoreElements(); ) {
                    entries.nextElement();
                    return charset;
                }
            }catch (Exception e) {}
        }
        return null;
    }
}
